19A - World Football Cup - CodeForces Solution


implementation *1400

Please click on ads to support us..

Python Code:

n = int(input())

scores = {}
for i in range(n):
    tName = input()
    scores[tName] = [0, 0, 0]

desLen = int(n*(n-1)/2)
for i in range(desLen):
    gameDes = input()
    sepDes = gameDes.split(' ')
    sepT = sepDes[0].split('-')
    sepS = sepDes[1].split(':')

    scores[sepT[0]][2] = scores[sepT[0]][2] + int(sepS[0])
    scores[sepT[1]][2] = scores[sepT[1]][2] + int(sepS[1])

    if int(sepS[0]) > int(sepS[1]):
        scores[sepT[0]][0] = scores[sepT[0]][0] + 3

        scores[sepT[0]][1] = scores[sepT[0]][1] + \
            (int(sepS[0]) - int(sepS[1]))

        scores[sepT[1]][1] = scores[sepT[1]][1] + \
            (int(sepS[1]) - int(sepS[0]))
    elif int(sepS[0]) < int(sepS[1]):
        scores[sepT[1]][0] = scores[sepT[1]][0] + 3

        scores[sepT[1]][1] = scores[sepT[1]][1] + \
            (int(sepS[1]) - int(sepS[0]))

        scores[sepT[0]][1] = scores[sepT[0]][1] + \
            (int(sepS[0]) - int(sepS[1]))
    else:
        scores[sepT[0]][0] = scores[sepT[0]][0] + 1

        scores[sepT[1]][0] = scores[sepT[1]][0] + 1

valArr = sorted(scores.values(), reverse=True)
keyArr = []

for i in range(0, int(len(valArr)/2)):
    keyArr.append(list(scores.keys())[
                  list(scores.values()).index(valArr[i])])

for i in sorted(keyArr):
    print(i)

C++ Code:

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

struct perf{std::string name; long pts, diff, scored;};

bool perfCompare(perf a, perf b){
    if(a.pts > b.pts){return true;}
    else if(a.pts == b.pts && a.diff > b.diff){return true;}
    else if(a.pts == b.pts && a.diff == b.diff && a.scored > b.scored){return true;}
    return false;
}

int main(){

    long n; std::cin >> n;
    std::map<std::string, perf> m;
    for(long p = 0; p < n; p++){
        std::string s; std::cin >> s;
        m[s].name = s; m[s].pts = m[s].diff = m[s].scored = 0;
    }

    for(long p = 0; p < n * (n - 1) / 2; p++){
        std::string names, goals; std::cin >> names >> goals;
        std::string xn(""), yn(""); bool dash(0);
        for(long p = 0; p < names.size(); p++){
            if(names[p] == '-'){dash = true;}
            else if(dash){yn += names[p];}
            else{xn += names[p];}
        }

        long xg(0), yg(0); bool colon(0);
        for(long p = 0; p < goals.size(); p++){
            if(goals[p] == ':'){colon = true;}
            else if(colon){yg = 10 * yg + (goals[p] - '0');}
            else{xg = 10 * xg + (goals[p] - '0');}
        }

        m[xn].scored += xg; m[yn].scored += yg;
        m[xn].diff += xg - yg; m[yn].diff += yg - xg;
        if(xg > yg){m[xn].pts += 3;}
        else if(xg < yg){m[yn].pts += 3;}
        else {m[xn].pts += 1; m[yn].pts += 1;}
    }

    std::vector<perf> v;
    for(std::map<std::string, perf>::iterator it = m.begin(); it != m.end(); it++){v.push_back(it->second);}
    sort(v.begin(), v.end(), perfCompare);
    std::vector<std::string> res(n / 2); for(long p = 0; p < n / 2; p++){res[p] = v[p].name;}
    sort(res.begin(), res.end());
    for(long p = 0; p < res.size(); p++){std::cout << res[p] << std::endl;}

    return 0;
}


Comments

Submit
0 Comments
More Questions

479C - Exams
1030A - In Search of an Easy Problem
158A - Next Round
71A - Way Too Long Words
160A - Twins
1A - Theatre Square
1614B - Divan and a New Project
791A - Bear and Big Brother
1452A - Robot Program
344A - Magnets
96A - Football
702B - Powers of Two
1036A - Function Height
443A - Anton and Letters
1478B - Nezzar and Lucky Number
228A - Is your horseshoe on the other hoof
122A - Lucky Division
1611C - Polycarp Recovers the Permutation
432A - Choosing Teams
758A - Holiday Of Equality
1650C - Weight of the System of Nested Segments
1097A - Gennady and a Card Game
248A - Cupboards
1641A - Great Sequence
1537A - Arithmetic Array
1370A - Maximum GCD
149A - Business trip
34A - Reconnaissance 2
59A - Word
462B - Appleman and Card Game